import { Injectable } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Routes } from '@angular/router';
import { UserRouteAccessService } from 'app/core';
import { of } from 'rxjs';
import { map } from 'rxjs/operators';
import { FinancialManage } from 'app/shared/model/financial-manage.model';
import { FinancialManageService } from './financial-manage.service';
import { FinancialManageComponent } from './financial-manage.component';
import { FinancialManageDetailComponent } from './financial-manage-detail.component';
import { FinancialManageUpdateComponent } from './financial-manage-update.component';
import { FinancialManageDeletePopupComponent } from './financial-manage-delete-dialog.component';
import { IFinancialManage } from 'app/shared/model/financial-manage.model';

@Injectable({ providedIn: 'root' })
export class FinancialManageResolve implements Resolve<IFinancialManage> {
    constructor(private service: FinancialManageService) {}

    resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        const id = route.params['id'] ? route.params['id'] : null;
        if (id) {
            return this.service.find(id).pipe(map((financialManage: HttpResponse<FinancialManage>) => financialManage.body));
        }
        return of(new FinancialManage());
    }
}

export const financialManageRoute: Routes = [
    {
        path: 'financial-manage',
        component: FinancialManageComponent,
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.financialManage.home.title'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'financial-manage/:id/view',
        component: FinancialManageDetailComponent,
        resolve: {
            financialManage: FinancialManageResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.financialManage.home.title'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'financial-manage/new',
        component: FinancialManageUpdateComponent,
        resolve: {
            financialManage: FinancialManageResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.financialManage.home.title'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'financial-manage/:id/edit',
        component: FinancialManageUpdateComponent,
        resolve: {
            financialManage: FinancialManageResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.financialManage.home.title'
        },
        canActivate: [UserRouteAccessService]
    }
];

export const financialManagePopupRoute: Routes = [
    {
        path: 'financial-manage/:id/delete',
        component: FinancialManageDeletePopupComponent,
        resolve: {
            financialManage: FinancialManageResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.financialManage.home.title'
        },
        canActivate: [UserRouteAccessService],
        outlet: 'popup'
    }
];
